package com.itheima.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * @ClassName CorsConfiguration
 * @Description TODO
 * @Author Shinelon
 * @Date DATE 2021/4/5 18:04
 */
@Configuration
public class HkzfCorsConfiguration {
    @Bean
    CorsFilter getCorsFilter(){
       CorsConfiguration corsConfiguration  = new CorsConfiguration();
        corsConfiguration.addAllowedOrigin("http://localhost:8080");
        corsConfiguration.addAllowedOrigin("http://localhost");
        corsConfiguration.addAllowedOrigin("http://47.106.85.120");

        corsConfiguration.setAllowCredentials(true);//允许cookkie
       corsConfiguration.addAllowedMethod("*");
       corsConfiguration.addAllowedHeader("*");//如何头信息
        //1.初始化配置对象
        UrlBasedCorsConfigurationSource corsConfigurationSource = new UrlBasedCorsConfigurationSource();
        corsConfigurationSource.registerCorsConfiguration("/**",corsConfiguration);
        return  new CorsFilter(corsConfigurationSource );
    }

}
